package com.gary.shiro.service;

import com.gary.shiro.param.LoginParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.springframework.stereotype.Service;

/**
 * @author peng_rui
 * @date 2022/3/26
 */
@Slf4j
@Service
public class LoginService {


    public void login(LoginParam param) {
        AuthenticationToken token = new UsernamePasswordToken(param.getUsername(), param.getPassword());
        //测试密码
        //SimpleHash simpleHash = new SimpleHash("md5", param.getPassword(), null, 8);
        //simpleHash.toHex();
        SecurityUtils.getSubject().login(token);
    }

    public void logout() {
        SecurityUtils.getSubject().logout();
    }
}
